package com.hsc.yalebao.tools;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import com.hsc.yalebao.base.CustomApplication;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.List;

public class BitmapLoader
{
  private static float hRadius = 5.0F;
  private static int iterations = 2;
  private static float vRadius = 5.0F;

  public static Bitmap BoxBlurFilter(Bitmap paramBitmap)
  {
    int i = paramBitmap.getWidth();
    int j = paramBitmap.getHeight();
    int[] arrayOfInt1 = new int[i * j];
    int[] arrayOfInt2 = new int[i * j];
    Bitmap localBitmap = Bitmap.createBitmap(i, j, Bitmap.Config.ARGB_8888);
    paramBitmap.getPixels(arrayOfInt1, 0, i, 0, 0, i, j);
    for (int k = 0; ; k++)
    {
      if (k >= iterations)
      {
        blurFractional(arrayOfInt1, arrayOfInt2, i, j, hRadius);
        blurFractional(arrayOfInt2, arrayOfInt1, j, i, vRadius);
        localBitmap.setPixels(arrayOfInt1, 0, i, 0, 0, i, j);
        return localBitmap;
      }
      blur(arrayOfInt1, arrayOfInt2, i, j, hRadius);
      blur(arrayOfInt2, arrayOfInt1, j, i, vRadius);
    }
  }

  public static void blur(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, float paramFloat)
  {
    int i = paramInt1 - 1;
    int j = (int)paramFloat;
    int k = 1 + j * 2;
    int[] arrayOfInt = new int[k * 256];
    int n;
    int i1;
    for (int m = 0; ; m++)
    {
      if (m >= k * 256)
      {
        n = 0;
        i1 = 0;
        if (i1 < paramInt2)
          break;
        return;
      }
      arrayOfInt[m] = (m / k);
    }
    int i2 = i1;
    int i3 = 0;
    int i4 = 0;
    int i5 = 0;
    int i6 = 0;
    int i7 = -j;
    label92: if (i7 > j);
    for (int i9 = 0; ; i9++)
    {
      if (i9 >= paramInt1)
      {
        n += paramInt1;
        i1++;
        break;
        int i8 = paramArrayOfInt1[(n + clamp(i7, 0, paramInt1 - 1))];
        i3 += (0xFF & i8 >> 24);
        i4 += (0xFF & i8 >> 16);
        i5 += (0xFF & i8 >> 8);
        i6 += (i8 & 0xFF);
        i7++;
        break label92;
      }
      paramArrayOfInt2[i2] = (arrayOfInt[i3] << 24 | arrayOfInt[i4] << 16 | arrayOfInt[i5] << 8 | arrayOfInt[i6]);
      int i10 = 1 + (i9 + j);
      if (i10 > i)
        i10 = i;
      int i11 = i9 - j;
      if (i11 < 0)
        i11 = 0;
      int i12 = paramArrayOfInt1[(n + i10)];
      int i13 = paramArrayOfInt1[(n + i11)];
      i3 += (0xFF & i12 >> 24) - (0xFF & i13 >> 24);
      i4 += ((0xFF0000 & i12) - (0xFF0000 & i13) >> 16);
      i5 += ((0xFF00 & i12) - (0xFF00 & i13) >> 8);
      i6 += (i12 & 0xFF) - (i13 & 0xFF);
      i2 += paramInt2;
    }
  }

  public static void blurFractional(int[] paramArrayOfInt1, int[] paramArrayOfInt2, int paramInt1, int paramInt2, float paramFloat)
  {
    float f1 = paramFloat - (int)paramFloat;
    float f2 = 1.0F / (1.0F + 2.0F * f1);
    int i = 0;
    int j = 0;
    if (j >= paramInt2)
      return;
    int k = j;
    paramArrayOfInt2[k] = paramArrayOfInt1[0];
    int m = k + paramInt2;
    for (int n = 1; ; n++)
    {
      int i1 = paramInt1 - 1;
      if (n >= i1)
      {
        paramArrayOfInt2[m] = paramArrayOfInt1[(paramInt1 - 1)];
        i += paramInt1;
        j++;
        break;
      }
      int i2 = i + n;
      int i3 = paramArrayOfInt1[(i2 - 1)];
      int i4 = paramArrayOfInt1[i2];
      int i5 = paramArrayOfInt1[(i2 + 1)];
      int i6 = 0xFF & i3 >> 24;
      int i7 = 0xFF & i3 >> 16;
      int i8 = 0xFF & i3 >> 8;
      int i9 = i3 & 0xFF;
      int i10 = 0xFF & i4 >> 24;
      int i11 = 0xFF & i4 >> 16;
      int i12 = 0xFF & i4 >> 8;
      int i13 = i4 & 0xFF;
      int i14 = 0xFF & i5 >> 24;
      int i15 = 0xFF & i5 >> 16;
      int i16 = 0xFF & i5 >> 8;
      int i17 = i5 & 0xFF;
      int i18 = i10 + (int)(f1 * (i6 + i14));
      int i19 = i11 + (int)(f1 * (i7 + i15));
      int i20 = i12 + (int)(f1 * (i8 + i16));
      int i21 = i13 + (int)(f1 * (i9 + i17));
      int i22 = (int)(f2 * i18);
      int i23 = (int)(f2 * i19);
      int i24 = (int)(f2 * i20);
      paramArrayOfInt2[m] = ((int)(f2 * i21) | (i22 << 24 | i23 << 16 | i24 << 8));
      m += paramInt2;
    }
  }

  public static int calculateInSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
  {
    int i = paramOptions.outHeight;
    int j = paramOptions.outWidth;
    int k = 1;
    int m;
    int n;
    if ((i > paramInt2) || (j > paramInt1))
    {
      m = i / 2;
      n = j / 2;
    }
    while (true)
    {
      if ((m / k <= paramInt2) || (n / k <= paramInt1))
        return k;
      k *= 2;
    }
  }

  public static int clamp(int paramInt1, int paramInt2, int paramInt3)
  {
    if (paramInt1 < paramInt2)
      return paramInt2;
    if (paramInt1 > paramInt3)
      return paramInt3;
    return paramInt1;
  }

  private static int computeInitialSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
  {
    double d1 = paramOptions.outWidth;
    double d2 = paramOptions.outHeight;
    int i;
    int j;
    if (paramInt2 == -1)
    {
      i = 1;
      if (paramInt1 != -1)
        break label60;
      j = 128;
      label31: if (j >= i)
        break label84;
    }
    label60: label84: 
    do
    {
      return i;
      i = (int)Math.ceil(Math.sqrt(d1 * d2 / paramInt2));
      break;
      j = (int)Math.min(Math.floor(d1 / paramInt1), Math.floor(d2 / paramInt1));
      break label31;
      if ((paramInt2 == -1) && (paramInt1 == -1))
        return 1;
    }
    while (paramInt1 == -1);
    return j;
  }

  public static int computeSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
  {
    int i = computeInitialSampleSize(paramOptions, paramInt1, paramInt2);
    if (i <= 8)
    {
      int j = 1;
      while (true)
      {
        if (j >= i)
          return j;
        j <<= 1;
      }
    }
    return 8 * ((i + 7) / 8);
  }

  public static Bitmap decodeSampledBitmapFromResource(Resources paramResources, int paramInt1, int paramInt2, int paramInt3)
  {
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(paramResources, paramInt1, localOptions);
    localOptions.inSampleSize = calculateInSampleSize(localOptions, paramInt2, paramInt3);
    localOptions.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(paramResources, paramInt1, localOptions);
  }

  public static Bitmap drawableToBitmap(Drawable paramDrawable)
  {
    int i = paramDrawable.getIntrinsicWidth();
    int j = paramDrawable.getIntrinsicHeight();
    if (paramDrawable.getOpacity() != -1);
    for (Bitmap.Config localConfig = Bitmap.Config.ARGB_8888; ; localConfig = Bitmap.Config.RGB_565)
    {
      Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);
      Canvas localCanvas = new Canvas(localBitmap);
      paramDrawable.setBounds(0, 0, i, j);
      paramDrawable.draw(localCanvas);
      return localBitmap;
    }
  }

  public static Bitmap getBitmapFromFile(String paramString, int paramInt1, int paramInt2)
  {
    if (paramString != null)
    {
      BitmapFactory.Options localOptions = null;
      if (paramInt1 > 0)
      {
        localOptions = null;
        if (paramInt2 > 0)
        {
          localOptions = new BitmapFactory.Options();
          localOptions.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(paramString, localOptions);
          localOptions.inSampleSize = computeSampleSize(localOptions, Math.min(paramInt1, paramInt2), paramInt1 * paramInt2);
          localOptions.inJustDecodeBounds = false;
        }
      }
      return BitmapFactory.decodeFile(paramString, localOptions);
    }
    return null;
  }

  public static int getFitBitmapHeight(Bitmap paramBitmap, int paramInt)
  {
    int i = paramBitmap.getWidth();
    int j = paramBitmap.getHeight();
    int k = (int)(paramInt / i * j);
    if ((paramBitmap != null) && (!paramBitmap.isRecycled()))
      paramBitmap.recycle();
    return k;
  }

  public static Bitmap getImageFromAssetsFile(String paramString)
  {
    Bitmap localBitmap = null;
    AssetManager localAssetManager = CustomApplication.app.getResources().getAssets();
    try
    {
      InputStream localInputStream = localAssetManager.open(paramString);
      BitmapFactory.Options localOptions = new BitmapFactory.Options();
      localOptions.inPreferredConfig = Bitmap.Config.RGB_565;
      localBitmap = BitmapFactory.decodeStream(localInputStream, null, localOptions);
      localInputStream.close();
      return localBitmap;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return localBitmap;
  }

  public static Bitmap getImageFromAssetsFileZoom(Context paramContext, String paramString)
  {
    Bitmap localBitmap = null;
    AssetManager localAssetManager = CustomApplication.app.getResources().getAssets();
    try
    {
      InputStream localInputStream = localAssetManager.open(paramString);
      BitmapFactory.Options localOptions = new BitmapFactory.Options();
      localOptions.inJustDecodeBounds = true;
      localOptions.inPurgeable = true;
      localOptions.inInputShareable = true;
      BitmapFactory.decodeStream(localInputStream, null, localOptions);
      float f1 = (0.0F + (Utility.getScreenWidth(paramContext) - UiUtil.dip2px(paramContext, 55.0F))) / 2.0F;
      float f2 = (int)(localOptions.outWidth / f1);
      if (f2 <= 0.0F)
        f2 = 1.0F;
      localOptions.inJustDecodeBounds = false;
      localOptions.inSampleSize = ((int)f2);
      localBitmap = BitmapFactory.decodeStream(localAssetManager.open(paramString), null, localOptions);
      localInputStream.close();
      return localBitmap;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return localBitmap;
  }

  public static String getPictureSize(List<String> paramList)
  {
    long l = 0L;
    Iterator localIterator = paramList.iterator();
    while (true)
    {
      if (!localIterator.hasNext())
      {
        NumberFormat localNumberFormat = NumberFormat.getNumberInstance();
        localNumberFormat.setMaximumFractionDigits(2);
        return localNumberFormat.format(l / 1048576.0D) + "M";
      }
      File localFile = new File((String)localIterator.next());
      if ((localFile.exists()) && (localFile.isFile()))
        l += localFile.length();
    }
  }

  // ERROR //
  public static String saveBitmapToLocal(Bitmap paramBitmap)
  {
    // Byte code:
    //   0: aload_0
    //   1: ifnonnull +5 -> 6
    //   4: aconst_null
    //   5: areturn
    //   6: aconst_null
    //   7: astore_1
    //   8: new 273	java/io/File
    //   11: dup
    //   12: ldc_w 294
    //   15: invokespecial 278	java/io/File:<init>	(Ljava/lang/String;)V
    //   18: astore_2
    //   19: aload_2
    //   20: invokevirtual 281	java/io/File:exists	()Z
    //   23: istore 9
    //   25: aconst_null
    //   26: astore_1
    //   27: iload 9
    //   29: ifne +8 -> 37
    //   32: aload_2
    //   33: invokevirtual 297	java/io/File:mkdirs	()Z
    //   36: pop
    //   37: new 273	java/io/File
    //   40: dup
    //   41: new 246	java/lang/StringBuilder
    //   44: dup
    //   45: invokespecial 298	java/lang/StringBuilder:<init>	()V
    //   48: aload_2
    //   49: invokevirtual 302	java/io/File:getAbsoluteFile	()Ljava/io/File;
    //   52: invokevirtual 305	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   55: ldc_w 307
    //   58: invokevirtual 267	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   61: aload_0
    //   62: invokevirtual 310	java/lang/Object:hashCode	()I
    //   65: i2d
    //   66: invokestatic 314	java/lang/Math:random	()D
    //   69: dadd
    //   70: invokestatic 316	java/lang/String:valueOf	(D)Ljava/lang/String;
    //   73: invokevirtual 267	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   76: invokevirtual 271	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   79: invokespecial 278	java/io/File:<init>	(Ljava/lang/String;)V
    //   82: astore 11
    //   84: aload 11
    //   86: invokevirtual 319	java/io/File:createNewFile	()Z
    //   89: pop
    //   90: new 321	java/io/FileOutputStream
    //   93: dup
    //   94: aload 11
    //   96: invokespecial 324	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   99: astore 13
    //   101: aload_0
    //   102: getstatic 330	android/graphics/Bitmap$CompressFormat:JPEG	Landroid/graphics/Bitmap$CompressFormat;
    //   105: bipush 80
    //   107: aload 13
    //   109: invokevirtual 334	android/graphics/Bitmap:compress	(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z
    //   112: pop
    //   113: aload 13
    //   115: invokevirtual 337	java/io/FileOutputStream:flush	()V
    //   118: aload 11
    //   120: invokevirtual 340	java/io/File:getAbsolutePath	()Ljava/lang/String;
    //   123: astore 15
    //   125: aload 13
    //   127: ifnull +91 -> 218
    //   130: aload 13
    //   132: invokevirtual 341	java/io/FileOutputStream:close	()V
    //   135: aload 15
    //   137: areturn
    //   138: astore 7
    //   140: aload 7
    //   142: invokevirtual 342	java/io/FileNotFoundException:printStackTrace	()V
    //   145: aload_1
    //   146: ifnull -142 -> 4
    //   149: aload_1
    //   150: invokevirtual 341	java/io/FileOutputStream:close	()V
    //   153: aconst_null
    //   154: areturn
    //   155: astore 8
    //   157: aload 8
    //   159: invokevirtual 200	java/io/IOException:printStackTrace	()V
    //   162: aconst_null
    //   163: areturn
    //   164: astore 5
    //   166: aload 5
    //   168: invokevirtual 200	java/io/IOException:printStackTrace	()V
    //   171: aload_1
    //   172: ifnull -168 -> 4
    //   175: aload_1
    //   176: invokevirtual 341	java/io/FileOutputStream:close	()V
    //   179: aconst_null
    //   180: areturn
    //   181: astore 6
    //   183: aload 6
    //   185: invokevirtual 200	java/io/IOException:printStackTrace	()V
    //   188: aconst_null
    //   189: areturn
    //   190: astore_3
    //   191: aload_1
    //   192: ifnull +7 -> 199
    //   195: aload_1
    //   196: invokevirtual 341	java/io/FileOutputStream:close	()V
    //   199: aload_3
    //   200: athrow
    //   201: astore 4
    //   203: aload 4
    //   205: invokevirtual 200	java/io/IOException:printStackTrace	()V
    //   208: goto -9 -> 199
    //   211: astore 16
    //   213: aload 16
    //   215: invokevirtual 200	java/io/IOException:printStackTrace	()V
    //   218: aload 15
    //   220: areturn
    //   221: astore_3
    //   222: aconst_null
    //   223: astore_1
    //   224: goto -33 -> 191
    //   227: astore_3
    //   228: aload 13
    //   230: astore_1
    //   231: goto -40 -> 191
    //   234: astore 5
    //   236: aconst_null
    //   237: astore_1
    //   238: goto -72 -> 166
    //   241: astore 5
    //   243: aload 13
    //   245: astore_1
    //   246: goto -80 -> 166
    //   249: astore 7
    //   251: aconst_null
    //   252: astore_1
    //   253: goto -113 -> 140
    //   256: astore 7
    //   258: aload 13
    //   260: astore_1
    //   261: goto -121 -> 140
    //
    // Exception table:
    //   from	to	target	type
    //   8	25	138	java/io/FileNotFoundException
    //   32	37	138	java/io/FileNotFoundException
    //   37	84	138	java/io/FileNotFoundException
    //   149	153	155	java/io/IOException
    //   8	25	164	java/io/IOException
    //   32	37	164	java/io/IOException
    //   37	84	164	java/io/IOException
    //   175	179	181	java/io/IOException
    //   8	25	190	finally
    //   32	37	190	finally
    //   37	84	190	finally
    //   140	145	190	finally
    //   166	171	190	finally
    //   195	199	201	java/io/IOException
    //   130	135	211	java/io/IOException
    //   84	101	221	finally
    //   101	125	227	finally
    //   84	101	234	java/io/IOException
    //   101	125	241	java/io/IOException
    //   84	101	249	java/io/FileNotFoundException
    //   101	125	256	java/io/FileNotFoundException
  }

  public static boolean verifyPictureSize(String paramString)
  {
    BitmapFactory.Options localOptions = new BitmapFactory.Options();
    localOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(paramString, localOptions);
    return (localOptions.outHeight <= 1280) && (localOptions.outWidth <= 720);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.tools.BitmapLoader
 * JD-Core Version:    0.6.2
 */